1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module soup.ClientContext;
26 
27 private import gio.IOStream;
28 private import gio.Socket;
29 private import gio.SocketAddress;
30 private import glib.Str;
31 private import glib.c.functions;
32 private import gobject.ObjectG;
33 private import soup.Address;
34 private import soup.AuthDomain;
35 private import soup.SSocket;
36 private import soup.c.functions;
37 public  import soup.c.types;
38 
39 
40 /**
41  * A #SoupClientContext provides additional information about the
42  * client making a particular request. In particular, you can use
43  * soup_client_context_get_auth_domain() and
44  * soup_client_context_get_auth_user() to determine if HTTP
45  * authentication was used successfully.
46  * 
47  * soup_client_context_get_remote_address() and/or
48  * soup_client_context_get_host() can be used to get information for
49  * logging or debugging purposes. soup_client_context_get_gsocket() may
50  * also be of use in some situations (eg, tracking when multiple
51  * requests are made on the same connection).
52  */
53 public class ClientContext
54 {
55 	/** the main Gtk struct */
56 	protected SoupClientContext* soupClientContext;
57 	protected bool ownedRef;
58 
59 	/** Get the main Gtk struct */
60 	public SoupClientContext* getClientContextStruct(bool transferOwnership = false)
61 	{
62 		if (transferOwnership)
63 			ownedRef = false;
64 		return soupClientContext;
65 	}
66 
67 	/** the main Gtk struct as a void* */
68 	protected void* getStruct()
69 	{
70 		return cast(void*)soupClientContext;
71 	}
72 
73 	/**
74 	 * Sets our main struct and passes it to the parent class.
75 	 */
76 	public this (SoupClientContext* soupClientContext, bool ownedRef = false)
77 	{
78 		this.soupClientContext = soupClientContext;
79 		this.ownedRef = ownedRef;
80 	}
81 
82 
83 	/** */
84 	public static GType getType()
85 	{
86 		return soup_client_context_get_type();
87 	}
88 
89 	/**
90 	 * Retrieves the #SoupAddress associated with the remote end
91 	 * of a connection.
92 	 *
93 	 * Deprecated: Use soup_client_context_get_remote_address(), which returns
94 	 * a #GSocketAddress.
95 	 *
96 	 * Returns: the #SoupAddress
97 	 *     associated with the remote end of a connection, it may be
98 	 *     %NULL if you used soup_server_accept_iostream().
99 	 */
100 	public Address getAddress()
101 	{
102 		auto __p = soup_client_context_get_address(soupClientContext);
103 
104 		if(__p is null)
105 		{
106 			return null;
107 		}
108 
109 		return ObjectG.getDObject!(Address)(cast(SoupAddress*) __p);
110 	}
111 
112 	/**
113 	 * Checks whether the request associated with @client has been
114 	 * authenticated, and if so returns the #SoupAuthDomain that
115 	 * authenticated it.
116 	 *
117 	 * Returns: a #SoupAuthDomain, or
118 	 *     %NULL if the request was not authenticated.
119 	 */
120 	public AuthDomain getAuthDomain()
121 	{
122 		auto __p = soup_client_context_get_auth_domain(soupClientContext);
123 
124 		if(__p is null)
125 		{
126 			return null;
127 		}
128 
129 		return ObjectG.getDObject!(AuthDomain)(cast(SoupAuthDomain*) __p);
130 	}
131 
132 	/**
133 	 * Checks whether the request associated with @client has been
134 	 * authenticated, and if so returns the username that the client
135 	 * authenticated as.
136 	 *
137 	 * Returns: the authenticated-as user, or %NULL if
138 	 *     the request was not authenticated.
139 	 */
140 	public string getAuthUser()
141 	{
142 		return Str.toString(soup_client_context_get_auth_user(soupClientContext));
143 	}
144 
145 	/**
146 	 * Retrieves the #GSocket that @client is associated with.
147 	 *
148 	 * If you are using this method to observe when multiple requests are
149 	 * made on the same persistent HTTP connection (eg, as the ntlm-test
150 	 * test program does), you will need to pay attention to socket
151 	 * destruction as well (eg, by using weak references), so that you do
152 	 * not get fooled when the allocator reuses the memory address of a
153 	 * previously-destroyed socket to represent a new socket.
154 	 *
155 	 * Returns: the #GSocket that @client is
156 	 *     associated with, %NULL if you used soup_server_accept_iostream().
157 	 *
158 	 * Since: 2.48
159 	 */
160 	public Socket getGsocket()
161 	{
162 		auto __p = soup_client_context_get_gsocket(soupClientContext);
163 
164 		if(__p is null)
165 		{
166 			return null;
167 		}
168 
169 		return ObjectG.getDObject!(Socket)(cast(GSocket*) __p);
170 	}
171 
172 	/**
173 	 * Retrieves the IP address associated with the remote end of a
174 	 * connection.
175 	 *
176 	 * Returns: the IP address associated with the remote
177 	 *     end of a connection, it may be %NULL if you used
178 	 *     soup_server_accept_iostream().
179 	 */
180 	public string getHost()
181 	{
182 		return Str.toString(soup_client_context_get_host(soupClientContext));
183 	}
184 
185 	/**
186 	 * Retrieves the #GSocketAddress associated with the local end
187 	 * of a connection.
188 	 *
189 	 * Returns: the #GSocketAddress
190 	 *     associated with the local end of a connection, it may be
191 	 *     %NULL if you used soup_server_accept_iostream().
192 	 *
193 	 * Since: 2.48
194 	 */
195 	public SocketAddress getLocalAddress()
196 	{
197 		auto __p = soup_client_context_get_local_address(soupClientContext);
198 
199 		if(__p is null)
200 		{
201 			return null;
202 		}
203 
204 		return ObjectG.getDObject!(SocketAddress)(cast(GSocketAddress*) __p);
205 	}
206 
207 	/**
208 	 * Retrieves the #GSocketAddress associated with the remote end
209 	 * of a connection.
210 	 *
211 	 * Returns: the #GSocketAddress
212 	 *     associated with the remote end of a connection, it may be
213 	 *     %NULL if you used soup_server_accept_iostream().
214 	 *
215 	 * Since: 2.48
216 	 */
217 	public SocketAddress getRemoteAddress()
218 	{
219 		auto __p = soup_client_context_get_remote_address(soupClientContext);
220 
221 		if(__p is null)
222 		{
223 			return null;
224 		}
225 
226 		return ObjectG.getDObject!(SocketAddress)(cast(GSocketAddress*) __p);
227 	}
228 
229 	/**
230 	 * Retrieves the #SoupSocket that @client is associated with.
231 	 *
232 	 * If you are using this method to observe when multiple requests are
233 	 * made on the same persistent HTTP connection (eg, as the ntlm-test
234 	 * test program does), you will need to pay attention to socket
235 	 * destruction as well (either by using weak references, or by
236 	 * connecting to the #SoupSocket::disconnected signal), so that you do
237 	 * not get fooled when the allocator reuses the memory address of a
238 	 * previously-destroyed socket to represent a new socket.
239 	 *
240 	 * Deprecated: use soup_client_context_get_gsocket(), which returns
241 	 * a #GSocket.
242 	 *
243 	 * Returns: the #SoupSocket that @client is
244 	 *     associated with.
245 	 */
246 	public SSocket getSocket()
247 	{
248 		auto __p = soup_client_context_get_socket(soupClientContext);
249 
250 		if(__p is null)
251 		{
252 			return null;
253 		}
254 
255 		return ObjectG.getDObject!(SSocket)(cast(SoupSocket*) __p);
256 	}
257 
258 	/**
259 	 * "Steals" the HTTP connection associated with @client from its
260 	 * #SoupServer. This happens immediately, regardless of the current
261 	 * state of the connection; if the response to the current
262 	 * #SoupMessage has not yet finished being sent, then it will be
263 	 * discarded; you can steal the connection from a
264 	 * #SoupMessage:wrote-informational or #SoupMessage:wrote-body signal
265 	 * handler if you need to wait for part or all of the response to be
266 	 * sent.
267 	 *
268 	 * Note that when calling this function from C, @client will most
269 	 * likely be freed as a side effect.
270 	 *
271 	 * Returns: the #GIOStream formerly associated
272 	 *     with @client (or %NULL if @client was no longer associated with a
273 	 *     connection). No guarantees are made about what kind of #GIOStream
274 	 *     is returned.
275 	 *
276 	 * Since: 2.50
277 	 */
278 	public IOStream stealConnection()
279 	{
280 		auto __p = soup_client_context_steal_connection(soupClientContext);
281 
282 		if(__p is null)
283 		{
284 			return null;
285 		}
286 
287 		return ObjectG.getDObject!(IOStream)(cast(GIOStream*) __p, true);
288 	}
289 }